<template>
  <!-- 商品详情 -->
  <div class="productdetails">
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in detailBanner" :key="item.id">
        <img
          :src="item.img_url"
          width="100%"
          :style="{ display: 'block' }"
          alt=""
        />
      </van-swipe-item>
    </van-swipe>
    <!-- 轮播图下的优惠 -->
    <van-row>
      <van-col span="8"><van-icon name="checked" />30天无忧退货</van-col>
      <van-col span="8"><van-icon name="checked" />48小时快速退费</van-col>
      <van-col span="8"><van-icon name="checked" />满88元免邮费 </van-col>
    </van-row>

    <!-- 产品信息 -->
    <div class="product_info">
      <h3>{{ info.name }}</h3>
      <div>{{ info.goods_brief }}</div>
      <p>{{ infoPrice | RMB }}</p>
    </div>

    <!-- 展示弹出层 -->
    <van-cell is-link @click="showPopup">展示弹出层</van-cell>
    <van-popup
      v-model="show"
      closeable
      position="bottom"
      :style="{ height: '30%' }"
    />

    <!-- 商品参数 -->
    <div class="canshu">
      <h3>商品参数</h3>

      <div v-for="(item, index) in attribute" :key="index" class="canshufooter">
        <small>{{ item.name }}</small>
        <big>{{ item.value }}</big>
      </div>
    </div>
    <!-- 商品简介 -->
    <div v-html="info.goods_desc" class="box"></div>

    <!-- 常见问题 -->

    <div class="issue">
      <div class="mytitle">
        <van-divider
          :style="{
            color: '#000',
            borderColor: '#000',
            padding: '0 16px',
            fontSize: '16px',
          }"
        >
          常见问题
        </van-divider>
      </div>
      <ul>
        <li v-for="item in issue" :key="item.id">
          <h3><i></i>{{ item.question }}</h3>
          <div class="issue-answer">{{ item.answer }}</div>
        </li>
      </ul>

      <!-- 大家都在看 -->
      <div class="allLook">
        <div class="mytitle">
          <van-divider
            :style="{
              color: '#000',
              borderColor: '#000',
              padding: '0 16px',
              fontSize: '16px',
            }"
          >
            大家都在看
          </van-divider>
        </div>
        <div class="new">
          <van-grid :border="false" :column-num="2" class="newProduct">
            <van-grid-item v-for="item in goodsList" :key="item.id">
              <van-image :src="item.list_pic_url" />
              <p>{{ item.name }}</p>
              <span>{{ item.retail_price | RMB }}</span>
            </van-grid-item>
          </van-grid>
        </div>
      </div>
    </div>

    <!-- 底部购物车组件 -->
    <AppGoodAction />
  </div>
</template>

<script>
import AppGoodAction from "@/components/AppGoodAction.vue";
import { GetProductDetailData, GetProductShop } from "@/request/api";
export default {
  data() {
    return {
      show: false,
      detailBanner: [],
      info: {},
      infoPrice: 0,
      attribute: [],
      issue: [],
      goodsList: [],
    };
  },
  methods: {
    showPopup() {
      this.show = true;
    },
  },
  filters: {
    RMB(val) {
      return `￥${val.toFixed(2)}元`;
    },
  },
  created() {
    let id = this.$route.query.id;
    GetProductDetailData({
      id,
    }).then((res) => {
      if (res.errno == "0") {
        // console.log(res.data);
        //轮播图的图片
        this.detailBanner = res.data.gallery;
        //产品信息
        this.info = res.data.info;
        this.infoPrice = res.data.info.retail_price;
        this.attribute = res.data.attribute;
        this.issue = res.data.issue;
      }
    });
    GetProductShop({
      id,
    }).then((res) => {
      if (res.errno == "0") {
        console.log(res.data.goodsList);
        this.goodsList = res.data.goodsList;
      }
    });
  },
  components: {
    AppGoodAction,
  },
};
</script>
 
<style lang = "less" scoped>
.productdetails {
  padding-bottom: 0.2rem;
}
.van-row {
  text-align: center;
  line-height: 0.3rem;
  font-size: 0.14rem;
  .van-icon {
    vertical-align: middle;
    color: darkred;
    font-size: 0.14rem;
    line-height: 0.3rem;
  }
}
.product_info {
  background: #fff;
  line-height: 0.4rem;
  text-align: center;
  padding: 0.2rem 0;
  border-bottom: 0.01rem solid #ccc;
  h3 {
    font-size: 0.2rem;
  }
  div {
    color: #666;
    font-size: 0.14rem;
  }
  p {
    color: darkred;
  }
}
.canshu {
  padding: 0.1rem 4%;
  margin-top: 0.2rem;
  background: #fff;
  .canshufooter {
    background: #efefef;
    width: 100%;
    border-radius: 5px;
    height: 40px;
    line-height: 40px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
  }
  small {
    width: 22%;
    color: #666;
    text-align: right;
    margin-right: 10px;
    font-size: smaller;
  }
  big {
    flex: 1;
    padding-right: 10px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}
.box {
  /deep/img {
    width: 100%;
    display: block;
  }
}
.issue {
  background: #fff;
  padding: 0 4%;
  h3 {
    position: relative;
    padding-left: 20px;
    margin-bottom: 10px;
  }
  i {
    width: 4px;
    height: 4px;
    background: darkred;
    position: absolute;
    top: 50%;
    left: 0;
    margin-top: -2px;
  }
  .issue-answer {
    padding-left: 20px;
    color: #666;
    font-size: 12px;
    padding-bottom: 10px;
  }
}
.mytitle {
  background-color: #fff;
}
.new {
  background-color: #fff;
  p {
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    overflow: hidden;
  }
  span {
    color: red;
    font-size: 0.16rem;
    margin-top: 0.05rem;
  }
}
.allLook {
  margin-bottom: 0.2rem;
}
</style>